package com.ktjy.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ktjy.mapper.SysRightMapperCh06;
import com.ktjy.mapper.SysRoleRightMapperCh06;
import com.ktjy.mapper.SysUserMapperCh06;
import com.ktjy.pojo.SysRight;
import com.ktjy.pojo.SysRoleRight;
import com.ktjy.pojo.SysUser;
import com.ktjy.pojo.UserPager;
import com.ktjy.pojo.vo.SysUserVo;
import com.ktjy.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapperCh06, SysUserVo> implements SysUserService {
    @Autowired
    SysUserMapperCh06 sysUserMapper;
    @Autowired
    SysRoleRightMapperCh06 sysRoleRightMapperCh06;

    @Override
    public SysUserVo login(String usrName, String usrPassword) {
        return sysUserMapper.login(usrName, usrPassword);
    }

    @Override
    public SysUserVo loginToken(String usrName) {
        return sysUserMapper.loginToken(usrName);
    }



    @Override
    public IPage<SysUserVo> getUserList(IPage<SysUserVo> page, SysUserVo sysUserVo) {
        return sysUserMapper.getUserList(page, sysUserVo);
    }

    @Override
    public int getUserAdd(SysUserVo sysUserVo) {
        if (sysUserVo!=null){
            sysUserVo.setUsrRoleId(sysUserVo.getRole().getRoleId());
            return sysUserMapper.insert(sysUserVo);
        }else {
            return 0;
        }
    }

    @Override
    public int getUserUpdate(SysUserVo sysUserVo) {
        return sysUserMapper.updateById(sysUserVo);
    }

    @Override
    public SysUserVo UserSelectById(Long usrId) {
        return sysUserMapper.selectById(usrId);
    }

    @Override
    public int getUserDelete(Integer id) {
        return sysUserMapper.deleteById(id);
    }

    @Override
    public List<SysRoleRight> getListSysRight(Long roleId) {
        QueryWrapper<SysRoleRight> sysRightQuery = new QueryWrapper<>();
        sysRightQuery.eq(roleId!=0,"rf_role_id" ,roleId);
        return sysRoleRightMapperCh06.selectList(sysRightQuery);
    }
}
